import React from 'react';
import { Space, Table, Tag } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { useEffect, useState } from "react";
import { apiRecord } from '@/api/api'
interface DataType {
  user_id:number,
  key:number
  clock_data: string,
  clock_period: string,
  work_hour: number,
  
}
const columns: ColumnsType<DataType> = [
  {
    title: '打卡日期',
    dataIndex: 'clock_data',
    key: 'clock_data',
    render: (text) => <a>{text}</a>,
  },
  {
    title: '打卡时段',
    dataIndex: 'clock_period',
    key: 'clock_period',
  },
  {
    title: '有效工时',
    dataIndex: 'work_hour',
    key: 'work_hour',
  },

];

const Record = () => {
  const [recordData, setRecordData] =  useState<DataType[]>([]);
  useEffect(() => {
    async function fetchData() {
      const result = await apiRecord()
      const transformedData = result.data.map((obj:any) => ({
        ...obj,
        key: obj.id,
      }));
      
      setRecordData(transformedData);
  }
    fetchData() 
  },[])
  return (
  
    <Table columns={columns} dataSource={recordData} />
  );
};
export default Record




